﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class information : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetBindDdl();
        }
        if (Session["UserName"] != null)
        {
            
            GetInfo();
        }
        else
        {
            Whir.Common.WebHelper.JsHelper.redirect(this.Page, "请先登录!", "Default.aspx");
        }
        
    }

    private void GetBindDdl()
    {
        DropDownList1.Items.Clear();
        DropDownList1.Items.Add(new ListItem("--请选择--", "0"));
        string sql = "select * from Whir_CommonCategory where ParentId=1";
        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.Query(sql).Tables[0];
        foreach (DataRow dr in dt.Rows)
        {
            DropDownList1.Items.Add(new ListItem(dr["CategoryName"].ToString(), dr["CategoryId"].ToString()));
        }

        DropDownList2.Items.Clear();
        DropDownList2.Items.Add(new ListItem("--请选择--", "0"));
        string sql2 = "select * from Whir_CommonCategory where ParentId=2";
        DataTable dt2 = Whir.SQLServerDAL.DbHelperSQL.Query(sql2).Tables[0];
        foreach (DataRow dr2 in dt2.Rows)
        {
            DropDownList2.Items.Add(new ListItem(dr2["CategoryName"].ToString(), dr2["CategoryId"].ToString()));
        }

    }
    private void GetInfo()
    {
        string sql = string.Format("select * from Whir_U_Users where LoginName='{0}' ", Session["UserName"].ToString());
        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.Query(sql).Tables[0];
        if (dt != null && dt.Rows.Count > 0)
        {
             
            txtName.Value=dt.Rows[0]["TrueName"].ToString();
            txtTel.Value=dt.Rows[0]["LinkTel"].ToString();
            txtCompanyAddress.Value=dt.Rows[0]["Address"].ToString();
            txtCompanyName1.Value = dt.Rows[0]["CompanyName"].ToString();
            txtWebSiteUrl.Value=dt.Rows[0]["WebSiteUrl"].ToString();
            //txtPostCode.Value=dt.Rows[0]["PostCode"].ToString();
            txtFax.Value=dt.Rows[0]["Fax"].ToString();
            //txtBussiness.Value=dt.Rows[0]["industry"].ToString();
            //string sex = dt.Rows[0]["sex"].ToString();

            //if (sex == "男")
            //{
            //    Sex1.Checked = true;
            //}
            //else
            //{
            //    Sex2.Checked = true;
            //}

            txtCompanyTel.Value=dt.Rows[0]["CompanyTel"].ToString();
            txtCompanyFax.Value=dt.Rows[0]["CompanyFax"].ToString();
           // txtQQ.Value=dt.Rows[0]["QQ"].ToString();
            txtMobile.Value=dt.Rows[0]["Mobie"].ToString();
            txtEmail.Value=dt.Rows[0]["Email"].ToString();


            txtProducts.Value = dt.Rows[0]["Products"].ToString();
            txtFRDB.Value = dt.Rows[0]["frdb"].ToString();
            txtYYZZ.Value = dt.Rows[0]["YYZZ"].ToString();
            txtZCZZ.Value = dt.Rows[0]["NewC"].ToString();
            txtNLS.Value = dt.Rows[0]["NLS"].ToString();
            txtNCZ.Value = dt.Rows[0]["NewD"].ToString();
            
            DropDownList1.SelectedValue = dt.Rows[0]["NewI"].ToString();
            DropDownList2.SelectedValue = dt.Rows[0]["characteristic"].ToString();
            RadioButtonList1.SelectedValue = dt.Rows[0]["zscq"].ToString();

            

        }

    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
       


        //string sex = "女";
        //if (Sex1.Checked == true)
        //    sex = "男";
        //else
        //    sex = "女";





        string sql = "update Whir_U_Users set CreateDate=@CreateDate,TrueName=@TrueName,LinkTel=@LinkTel,Address=@Address,CompanyName=@CompanyName,WebSiteUrl=@WebSiteUrl,PostCode=@PostCode,Fax=@Fax,industry=@industry,sex=@sex,CompanyTel=@CompanyTel,CompanyFax=@CompanyFax,QQ=@QQ,Mobie=@Mobie,Email=@Email,NewH=@NewH,NewI=@NewI,characteristic=@characteristic,NewD=@NewD,NLS=@NLS,NewC=@NewC,zscq=@zscq,Products=@Products,frdb=@frdb,YYZZ=@YYZZ where LoginName=@LoginName";

        SqlParameter[] pa =
        {
            new SqlParameter("@CreateDate",DateTime.Now),
            new SqlParameter("@TrueName",txtName.Value),
            new SqlParameter("@LinkTel",txtTel.Value),
            new SqlParameter("@Address",txtCompanyAddress.Value),
            new SqlParameter("@CompanyName",txtCompanyName1.Value),
            new SqlParameter("@WebSiteUrl",txtWebSiteUrl.Value),
            new SqlParameter("@PostCode",""),
            new SqlParameter("@Fax",txtFax.Value),
            new SqlParameter("@industry",""),
            new SqlParameter("@sex",""),
            new SqlParameter("@CompanyTel",txtCompanyTel.Value),
            new SqlParameter("@CompanyFax",txtCompanyFax.Value),
            new SqlParameter("@QQ",""),
            new SqlParameter("@Mobie",txtMobile.Value),
            new SqlParameter("@Email",txtEmail.Value),

            new SqlParameter("@NewH",txtCompanyName1.Value),                                         //单位名称
            new SqlParameter("@NewI",DropDownList1.SelectedValue),                      //单位类型
            new SqlParameter("@characteristic",DropDownList2.SelectedValue),            //单位特性
            new SqlParameter("@NewD",txtNCZ.Value),                                     //年产值（万元）
            new SqlParameter("@NLS",txtNLS.Value),                                      //年利税
            new SqlParameter("@NewC",txtZCZZ.Value),                                    //注册资金（万元）
            new SqlParameter("@zscq",RadioButtonList1.SelectedValue),                   //是否拥有知识产权
            new SqlParameter("@Products",txtProducts.Value),                             //主营产品
            new SqlParameter("@frdb",txtFRDB.Value),                             //法人代表
            new SqlParameter("@YYZZ",txtYYZZ.Value),                             //营业执照
             
            new SqlParameter("@LoginName",Session["UserName"].ToString())
        };
        int count = Whir.SQLServerDAL.DbHelperSQL.ExecuteSql(sql, pa);
        if (count > 0)
        {
            // Session["UserName"] = UserName;
             Whir.Common.WebHelper.JsHelper.redirect(this.Page, "修改资料成功！", "login.aspx");
            

        }
        else { Whir.Common.WebHelper.JsHelper.Alert(this.Page, "修改资料失败!"); }

    }
}
